package com.sk.bilibili.view.fragment.main.home.dynamic;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.main.dynamic.DynamicAdapter;
import com.sk.bilibili.adapter.vlayout.main.dynamic.SearchAdapter;
import com.sk.bilibili.bean.Dynamic;
import com.sk.bilibili.bean.Focus;
import com.sk.bilibili.callBack.DynamicCallBack;
import com.sk.bilibili.callBack.SearchClickCallBack;
import com.sk.bilibili.model.fragment.main.home.dynamic.HotModel;
import com.sk.bilibili.view.activity.DynamicActivity;
import com.sk.bilibili.view.activity.DynamicSearchActivity;
import com.sk.bilibili.view.activity.MemberActivity;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.activity.VideoSetActivity;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class HotFragment extends BaseRefreshFragment<HotModel> implements DynamicCallBack, SearchClickCallBack {

    private DynamicAdapter dynamicAdapter;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        adapter.addAdapter(new SearchAdapter(getContext(),this));
        dynamicAdapter = new DynamicAdapter(getContext(), this);
        adapter.addAdapter(dynamicAdapter);
    }

    @Override
    public void onMemberClick(Integer id) {
        MemberActivity.start(getContext(),id);
    }

    @Override
    public void onVideoSetClick(Integer id) {
        VideoSetActivity.start(getContext(),id);
    }

    @Override
    public void onThemClick(Integer id) {
        ThemActivity.start(getContext(),id);
    }

    @Override
    public void onForwardClick(int type, Integer targetId) {
        DynamicActivity.start(getContext(),type,targetId);
    }

    @Override
    public void onPraiseClick(int type, Integer targetId) {
        model.praise(type,targetId);
    }

    @Override
    public void onFocusClick(Integer id) {
        model.switchFocus(id);
    }

    public void praiseSuccess() {
        toast("操作成功");
    }

    public void switchFocusSuccess(Focus focus) {
        toast(focus==null?"取消关注成功":"关注成功");
    }

    public void refreshSuccess(List<Dynamic> records) {
        dynamicAdapter.setData(records);
        cancelRefresh();
    }

    public void loadSuccess(List<Dynamic> records) {
        dynamicAdapter.addData(records);
    }

    @Override
    public void onClickSearch() {
        DynamicSearchActivity.start(getContext());
    }

}